<script>
  import {
    mapActions,
    mapMutations
  } from 'vuex'
  import {
    connectWebSocket
  } from '@/utils/utils.js'
  import store from './store/store'
  export default {
    onLaunch: function() {
      console.log('App Launch')
      const storeToken = this.$store.state.m_user.token;
      if (storeToken && storeToken !== '') {
        console.log('检测到有效 Token，执行初始化');
        this.initAppPermissions();
        connectWebSocket()
      }
    },
    onShow: function() {
      console.log('App Show')
    },
    onHide: function() {
      console.log('App Hide')
      // 移除所有的监听事件
    },
    methods: {
      ...mapActions('permission', ['initPermissions']),
      ...mapMutations('m_user', ['clearUserInfo']),
      async initAppPermissions() {
        try {
          await this.initPermissions()
        } catch (error) {
          console.error('初始化权限失败:', error)
          this.clearUserInfo()
          uni.reLaunch({
            url: '/pages/my/my'
          })
        }
      }
    }
  }
</script>

<style lang="scss">
</style>